import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig((commd) =>{
  console.log(commd)
  return {
    plugins: [react()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src')
      }
    },
    base: commd.mode === 'devlopment'? '': 'production',
    server: {
      host: '0.0.0.0',
      port:  8080,
      // strictPort: true,
      // cors: true,
      // hmr: true,
      // proxy: {
      //   '/api': {
      //     target: '',
      //     ws: false,
      //     changeOrigin: true,
      //     rewrite: path => path.replace(/^\/api/, '')
      //   }
      // }
    },
    build: {
      cssCodeSplit: true,
      chunkSizeWarningLimit: 2000,
      assetsInlineLimit: 4000,
      sourcemap: false,
      minify: 'terser', // 代码混淆
      assetsDir: 'static/assets',
      // 在生产环境移除console.log
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true,
        },
      },
    }
  }
})
